home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Plotting / aa_Intel_Only / Gnuplot / GnuplotSource / StatusTics.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  6.0 KB  |  329 lines

  1. /*
  2.  *  Copyright (C) 1993  Robert Davis
  3.  *
  4.  *  This program is free software; you can redistribute it and/or
  5.  *  modify it under the terms of Version 2, or any later version, of 
  6.  *  the GNU General Public License as published by the Free Software 
  7.  *  Foundation.
  8.  */
  9.  
  10.  
  11. static char RCSId[]="$Id: StatusTics.m,v 1.4 1993/05/04 16:22:53 davis Exp $";
  12.  
  13. #import <stdlib.h>
  14.  
  15. #import "DoubleValueSortedList.h"
  16. #import "StatusTics.h"
  17. #import "TicObject.h"
  18.  
  19. /* structs from plot.h */
  20.  
  21. struct ticdef {
  22.     int type;                /* one of three constants    */
  23.     union {
  24.     struct {            /* for TIC_SERIES        */
  25.         double start, incr;
  26.         double end;
  27.     } series;
  28.     struct ticmark *user;        /* for TIC_USER            */
  29.     } def;
  30. };
  31.  
  32. struct ticmark {
  33.     double position;            /* where on axis is this    */
  34.     char *label;            /* optional string label    */
  35.     struct ticmark *next;        /* linked list            */
  36. };
  37.  
  38.  
  39.  
  40. extern int tic_in;            /* s_tics_in            */
  41. extern int xtics, ytics, ztics;        /* s_ticsCoord[]        */
  42. extern struct ticdef xticdef;        /* s_ticdefCoord[]        */
  43. extern struct ticdef yticdef;
  44. extern struct ticdef zticdef;
  45.  
  46. /*
  47.  *  Frees the list of ticmarks whose head is pointed to by t and sets
  48.  *  t to NULL.
  49.  */
  50. static void _freeLinkedList(struct ticmark **t)
  51. {
  52.     struct ticmark *cur;
  53.  
  54.     while (*t) {
  55.     cur = *t;
  56.     *t = (*t)->next;
  57.     free (cur);
  58.     }
  59.  
  60.     *t = NULL;
  61.     return;
  62. }
  63.  
  64.  
  65.  
  66. @implementation Status (Tics)
  67.  
  68. - initTics
  69. {
  70.     int counter;
  71.  
  72.     for (counter = 0 ; counter < 3 ; counter++)
  73.     ticDefs[counter] = nil;
  74.  
  75.     return self;
  76. }
  77.  
  78.  
  79. - freeTics
  80. {
  81.     int    counter;
  82.  
  83.     for (counter = 0 ; counter < 3 ; counter++)
  84.     if (ticDefs[counter])
  85.         [[ticDefs[counter] freeObjects] free];
  86.  
  87.     return self;
  88. }
  89.  
  90.  
  91. - resetCurrentTics
  92. {
  93.     int counter;
  94.  
  95.     for (counter = 0 ; counter < 3 ; counter++)  {
  96.     s_ticsCoord[counter] = 1;
  97.     s_ticTypeCoord[counter] = TIC_COMPUTED;
  98.     s_ticSeriesCoord[counter].start = -10.0;
  99.     s_ticSeriesCoord[counter].incr = 5.0;
  100.     s_ticSeriesCoord[counter].end = 10.0;
  101.     if (ticDefs[counter])
  102.         [ticDefs[counter] freeObjects];
  103.     else
  104.         ticDefs[counter] = [[DoubleValueSortedList allocFromZone:zone]
  105.                                init];
  106.     }
  107.  
  108.     s_tics_in = YES;
  109.  
  110.     return self;
  111. }
  112.  
  113.  
  114. - applyCurrentTics
  115. {
  116.     int            count;
  117.     struct ticmark    *new;
  118.     id            tic;
  119.     struct ticdef    *ticd[3] = {&xticdef, &yticdef, &zticdef};
  120.     int            i;
  121.  
  122.     tic_in = s_tics_in;
  123.     xtics = s_ticsCoord[X_TAG];
  124.     ytics = s_ticsCoord[Y_TAG];
  125.     ztics = s_ticsCoord[Z_TAG];
  126.  
  127.     for (i = 0; i <= 2; i++) {
  128.  
  129.     switch (s_ticTypeCoord[i]) {
  130.     case TIC_SERIES:
  131.         ticd[i]->def.series.start = s_ticSeriesCoord[i].start;
  132.         ticd[i]->def.series.incr = s_ticSeriesCoord[i].incr;
  133.         ticd[i]->def.series.end = s_ticSeriesCoord[i].end;
  134.         break;
  135.     case TIC_USER:
  136.         if (ticd[i]->type == TIC_USER)
  137.         _freeLinkedList (&(ticd[i]->def.user));
  138.         else
  139.         ticd[i]->def.user = NULL;
  140.         if ((count = [ticDefs[i] count] - 1) >= 0) {
  141.         new = ticd[i]->def.user = malloc (sizeof (struct ticmark));
  142.         while (count >= 0) {
  143.             new->position = [tic = [ticDefs[i] objectAt:count]
  144.                      doubleValue];
  145.             new->label = (char *) [tic stringValue];
  146.             if (count--) {
  147.             new->next = malloc (sizeof (struct ticmark));
  148.             new = new->next;
  149.             } else
  150.             new->next = NULL;
  151.         }
  152.         break;
  153.         }
  154.     }
  155.     ticd[i]->type = s_ticTypeCoord[i];
  156.  
  157.     }
  158.  
  159.     return self;
  160. }
  161.  
  162.  
  163. - grabCurrentTics
  164. {
  165.     int            count, t;
  166.     struct ticmark    *cur;
  167.     id            tic;
  168.     struct ticdef    *ticd[3] = {&xticdef, &yticdef, &zticdef};
  169.     int            i;
  170.  
  171.     s_tics_in = tic_in;
  172.     s_ticsCoord[X_TAG] = xtics;
  173.     s_ticsCoord[Y_TAG] = ytics;
  174.     s_ticsCoord[Z_TAG] = ztics;
  175.  
  176.     for (i = 0; i <= 2; i++) {
  177.  
  178.     switch (s_ticTypeCoord[i] = ticd[i]->type) {
  179.     case TIC_SERIES:
  180.         s_ticSeriesCoord[i].start = ticd[i]->def.series.start;
  181.         s_ticSeriesCoord[i].incr = ticd[i]->def.series.incr;
  182.         s_ticSeriesCoord[i].end = ticd[i]->def.series.end;
  183.         break;
  184.     case TIC_USER:
  185.         count = [ticDefs[i] count] - 1;
  186.         t = 0;
  187.         for (cur = ticd[i]->def.user ; cur != NULL ; cur = cur->next) {
  188.         if (t <= count) {
  189.             [tic = [ticDefs[i] objectAt:t]
  190.                      setDoubleValue:cur->position];
  191.             [tic setStringValue:cur->label];
  192.         } else {
  193.             TicObject *tobj = [[TicObject allocFromZone:zone]
  194.                          initFromString:cur->label
  195.                             doubleValue:cur->position];
  196.             if ([ticDefs[i] addObjectIfDoubleAbsent:tobj]
  197.             == NX_NOT_IN_LIST)
  198.             [tobj free];
  199.  
  200.         }
  201.         t++;
  202.         }
  203.         break;
  204.     }
  205.  
  206.     }
  207.  
  208.     return self;
  209. }
  210.  
  211.  
  212. - setTicsIn:(BOOL) cond
  213. {
  214.     if (s_tics_in != cond) {
  215.     s_tics_in = cond;
  216.     [self reportSettingsChange:self];
  217.     }
  218.     return self;
  219. }
  220.  
  221.  
  222. - (BOOL) ticsIn
  223. {
  224.     return s_tics_in;
  225. }
  226.  
  227.  
  228.  
  229. - setTicsCoord:(int)coord isOn:(BOOL)isOn
  230. {
  231.     if (s_ticsCoord[coord] != isOn) {
  232.     s_ticsCoord[coord] = isOn;
  233.     [self reportSettingsChange:self];
  234.     }
  235.     return self;
  236. }
  237.  
  238.  
  239. - (BOOL) ticsCoord:(int)coord
  240. {
  241.     return s_ticsCoord[coord];
  242. }
  243.  
  244.  
  245.  
  246. - setTicTypeCoord:(int)coord to:(int)anInt
  247. {
  248.     if (s_ticTypeCoord[coord] != anInt) {
  249.     s_ticTypeCoord[coord] = anInt;
  250.     [self reportSettingsChange:self];
  251.     }
  252.     return self;
  253. }
  254.  
  255.  
  256.  
  257. - (int)ticTypeCoord:(int)coord
  258. {
  259.     return s_ticTypeCoord[coord];
  260. }
  261.  
  262.  
  263.  
  264. - setTicStartCoord:(int)coord to:(double)aDouble
  265. {
  266.     if (s_ticSeriesCoord[coord].start != aDouble) {
  267.     s_ticSeriesCoord[coord].start = aDouble;
  268.     [self reportSettingsChange:self];
  269.     }
  270.     return self;
  271. }
  272.  
  273.  
  274. - (double)ticStartCoord:(int)coord
  275. {
  276.     return s_ticSeriesCoord[coord].start;
  277. }
  278.  
  279.  
  280.  
  281. - setTicEndCoord:(int)coord to:(double)aDouble
  282. {
  283.     if (s_ticSeriesCoord[coord].end != aDouble) {
  284.     s_ticSeriesCoord[coord].end = aDouble;
  285.     [self reportSettingsChange:self];
  286.     }
  287.     return self;
  288. }
  289.  
  290.  
  291. - (double)ticEndCoord:(int)coord
  292. {
  293.     return s_ticSeriesCoord[coord].end;
  294. }
  295.  
  296.  
  297.  
  298. - setTicIncrementCoord:(int)coord to:(double)aDouble
  299. {
  300.     if (s_ticSeriesCoord[coord].incr != aDouble) {
  301.     s_ticSeriesCoord[coord].incr = aDouble;
  302.     [self reportSettingsChange:self];
  303.     }
  304.     return self;
  305. }
  306.  
  307.  
  308. - (double)ticIncrementCoord:(int)coord
  309. {
  310.     return s_ticSeriesCoord[coord].incr;
  311. }
  312.  
  313.  
  314.  
  315. - (DoubleValueSortedList *)ticDefsCoord:(int)coord
  316. {
  317.     return ticDefs[coord];
  318. }
  319.  
  320.  
  321.  
  322. // Shuts up compiler
  323. - (const char *) rcsid
  324. {
  325.     return RCSId;
  326. }
  327.  
  328. @end
  329.